import { Init, Provide } from '@midwayjs/decorator';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository, QueryRunner } from 'typeorm';
import { DemoUserInfoEntity } from '../entity/info';
import { DictInfoEntity } from './../../dict/entity/info';
/**
 * demo模块-用户信息服务
 */
@Provide()
export class DemoUserInfoService extends BaseService {
  @InjectEntityModel(DemoUserInfoEntity)
  demoUserInfoEntity: Repository<DemoUserInfoEntity>;

  @InjectEntityModel(DictInfoEntity)
  dictInfoEntity: Repository<DictInfoEntity>;

  @Init()
  async init() {
    await super.init();
    this.setEntity(this.demoUserInfoEntity);
  }

  async add(param: any, queryRunner?: QueryRunner){
    let itemLabels = await this.dictInfoEntity.findOneBy({value:param.labels})
    param.liveDuration = 0
    param.soundWave = 0
    param.giftCount = 0
    param.orderCount = 0
    param.labelsName = itemLabels.name
    const result: any = await super.add(param);
    return {
      id:result
    }
  }

  async update(param: any, queryRunner?: QueryRunner){
    let itemLabels = await this.dictInfoEntity.findOneBy({value:param.labels})
    param.labelsName = itemLabels.name
    const result: any = await super.update(param);
    return param
  }
}
